<?php 
class navigatorComponent extends sfComponent{
	public function execute($request){
		$account = $this->getUser()->getAttribute('admin.accounts',array());
		if(!is_array($account) ||  count($account)!=3 || empty($account['login_user']) || intval($account['id'])<=0 || intval($account['admin_type'])<0 ||intval($account['admin_type'])>2 ){
			echo 'Not Login';
			return sfView::NONE;
		}
		//checking authentication
		$path = $request->getParameter('path', '');
		$max_depth = $request->getParameter('max_depth', 0);
		$str = ($request->isSecure()?'https://':'http://').$_SERVER['HTTP_HOST'].'/admin/uploadControl/directories?directory_path='.$path.'&max_depth='.$max_depth;
		$json_structure = file_get_contents($str);
		$data = json_decode($json_structure,true);
		echo '<ul id="red" class="filetree vi-treeview">';
		foreach($data as $item){
			echo '<li data-path="',$item['path'],'"><span class="folder">',$item['name'],'</span>';
			$this->getItem($item['children']);
			echo '</li>';
		}
		echo '</ul>';
		return sfView::NONE;
	}
	private function getItem($data){
		if(!is_array($data) || count($data)<=0) return;
		echo '<ul>';
		foreach($data as $item){
			echo '<li data-path="',$item['path'],'"><span class="folder">',$item['name'],'</span>';
			$this->getItem($item['children']);
			echo '</li>';
		}
		echo '</ul>';
	}
}